<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
    String id = request.getParameter("id") == null ? "" : request.getParameter("id");
    boolean isAdd = "".equals(id);
    int flag = 0;
    if(!isAdd){
    	flag = 1;
    }
%>

<html>
	<head>
		<title><%=isAdd?"新建分包":"编辑分包商" %></title>
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
			.tdg{
			padding-top:10px;
			padding-bottom:5px;
			font-size: 12px;
			background-color: #c0ebd7;
			width:20%;
		}
		.tdb{
			padding:5px;
			width:30%;
		}
		</style>
	</head>
	<script type="text/javascript">	
		var flag = '<%=flag%>';
		$(function(){
	
			if(flag == '1'){
				$('#ff').form("load",'<%=contextPath %>/springMVC/crm/getWorkerById?id=<%=id%>');
			}
		});
		
		function doSubmit(obj){
			var type_id = $('#type_id').val();
			if(!checkNullOREmpty(type_id,"分包商分类")){return;}
			var worker_company = $('#worker_company').val();
			if(!checkNullOREmpty(worker_company,"分包商名称")){return;}
			var contact = $('#contact').val();
			var worker_person = $('#worker_person').val();
		
			
			var param = "type_id="+type_id+"&worker_company="+worker_company+"&contact="+contact+"&worker_person="+worker_person;
			$(obj).hide();
			if(flag == '0'){
				$.ajax({
					type:'POST',
					url:'<%=contextPath %>/springMVC/crm/addWorker',
					data:param,
					success:function(rtJson){
						if (rtJson.rtState == '0'){
							eval('window.opener.<%=callback%>();');
							window.close();
						}else{
							$(obj).show();
							warningInfo(rtJson.rtMsrg);
						}
					}
				});
			}
			else{
				param=param+"&id=<%=id%>";
				$.ajax({
					type:'POST',
					url:'<%=contextPath %>/springMVC/crm/updateWorker',
					data:param,
					success:function(rtJson){
						if (rtJson.rtState == '0'){
							eval('window.opener.<%=callback%>();');
							window.close();
						}else{
							$(obj).show();
							warningInfo(rtJson.rtMsrg);
						}
					}
				});
			}
		}
		
	</script>
	<body>
		<form id="ff" method="POST">
		<div style="width:90%;padding-left:50px;margin-top:50px">
			<table  style="border-collapse: collapse;" width="100%" border="1px" bordercolor="#0eb83a">
				<tr>
					<td align="right"  nowrap class="td1">
						分类：
					</td>
					<td class="td2" nowrap>
						<select id="type_id"  name="type_id" style="width:200px;" onchange="doSearch()">   
	    					 <option value=""></option> 
	    					<option value="0">内部班组</option>   
	    					<option value="1">外部分包商</option>   
						</select>  
					</td>
				</tr>
				<tr>
					<td align="right"  nowrap class="td1">
						分包商名称：
					</td>
					<td class="td2" nowrap >
						<input type="text" id="worker_company" name="worker_company"  class="easyui-validatebox" data-options="required:true">
					</td>
				</tr>
				<tr>
					<td align="right"  nowrap class="td1">
						负责人：
					</td>
					<td class="td2" nowrap >
						<input id="worker_person" name="worker_person"/>
					</td>
				</tr>
				<tr>
					<td align="right"  nowrap class="td1">
						联系方式：
					</td>
					<td class="td2" nowrap >
						<input id="contact" name="contact" />
					</td>
				</tr>
				
				
				<tr>
					<td align="right" nowrap class="td1">
					</td>
					<td  nowrap colspan="5">
						<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:false" onclick="doSubmit(this);">保存</a>
						<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:false" onclick="javascript:window.close();">关闭</a>
					</td>
				</tr>
				
 			</table>
		</div>
		</form>
	</body>
</html>
